import axios from 'axios'

const ajax = axios.create({
})

ajax.interceptors.request.use(config => {
  // console.log(config)
  config.headers.Authorization = window.sessionStorage.getItem('token')
  // console.log(config)
  return config
})

export const login = (username, password) => ajax.put(`v1/login?username=${username}&password=${password}`)
export const getMenuList = () => ajax.get('v1/menus')
// *获取用户列表
export const getUsers = (queryInfo) => ajax.get('v1/users', { params: queryInfo })
// export const getUsers = (queryInfo) => ajax.get('users?query=&pagenum=1&pagesize=5')
// *更改用户状态
export const changUserState = (id, state) => ajax.put(`v1/users/${id}/state/${state}`)
// *添加用户
export const addUser = (addForm) => ajax.post('v1/users', addForm)
// *根据 ID 查询用户信息
export const getUsersInfo = (id) => ajax.get('v1/users/' + id)
// *编辑用户提交
export const putEditUserInfo = (id, email, mobile) => ajax.put('v1/users/' + id, { email, mobile })
// *删除单个用户
export const deleteUser = (id) => ajax.delete('v1/users/' + id)
// *获取所有权限列表
export const getRightsList = () => ajax.get('v1/rights/list')
// *获取所有权限树状列表
export const getRightsListTree = () => ajax.get('v1/rights/tree')
// *获取角色列表
export const getRolesList = () => ajax.get('v1/roles')
// *添加用户角色
export const addRolsInfo = (addrole) => ajax.post('v1/roles', addrole)
// *select分配角色
export const setRole = (roleId, id) => ajax.put(`v1/users/${roleId}/role`, { rid: id })
// *根据ID查询用户角色
export const getRoleById = (id) => ajax.get('v1/roles/' + id)
// *编辑提交角色
export const putEditRole = (id, editRole) => ajax.put('v1/roles/' + id, editRole)
// *树状控件角色授权
export const allotRights = (treeId, idStr) => ajax.post(`v1/roles/${treeId}/rights`, { rids: idStr })
// *删除用户角色
export const delRoleInfo = (id) => ajax.delete('v1/roles/' + id)
// *删除角色指定权限
export const delRoleRight = (roleId, rightId) => ajax.delete(`v1/roles/${roleId}/rights/${rightId}`)
// *1.6.1. 商品分类数据列表
export const getCateList = (queryInfo = null) => ajax.get('v1/categories', { params: queryInfo })
// *1.6.2. 添加分类
export const addGoodCate = (queryInfo) => ajax.post('v1/categories', queryInfo)
//* 1.6.4. 编辑提交分类
export const putGoodsCategories = (id, name) => ajax.put(`v1/categories/${id}`, { cat_name: name })
//* 1.6.5. 删除分类
export const deleteGoodscategorie = (id) => ajax.delete(`v1/categories/${id}`)
//* 1.7.1. 参数列表
export const getAttributes = (id, type) => ajax.get(`v1/categories/${id}/attributes`, { params: { sel: type } })
//* 1.7.2. 添加动态参数或者静态属性
export const postAttributes = (id, name, sel) => ajax.post(`v1/categories/${id}/attributes`, { attr_name: name, attr_sel: sel })
//* 1.7.3. 删除参数
export const deleteCategoriesAttr = (id, attrid) => ajax.delete(`v1/categories/${id}/attributes/${attrid}`)
//* 1.7.5. 编辑提交参数
export const putCategoriesAttr = (id, attrId, name, sel, vals) => ajax.put(`v1/categories/${id}/attributes/${attrId}`, { attr_name: name, attr_sel: sel, attr_vals: vals })
//* 1.8.1. 商品列表数据
export const getGoodsList = (queryIonfo) => ajax.get('v1/goods', { params: queryIonfo })
//* 1.8.5. 删除商品
export const delGood = (id) => ajax.delete(`v1/goods/${id}`)
//* 1.11.1.  基于时间统计的折线图
export const getReports = () => ajax.get('v1/reports/type/1')
// ^数据可视化
// ^1.seller
export const getSellerData = () => ajax.get('api/seller')
export const getTrendrData = () => ajax.get('api/Trend')
export const getMapData = () => ajax.get('api/map')
export const getRankData = () => ajax.get('api/rank')
export const getHotData = () => ajax.get('api/hotproduct')
export const getStockData = () => ajax.get('api/Stock')
